//
//  UnbundlingViewController.m
//  MoXiProject
//
//  Created by 周筱雯 on 2017/7/6.
//  Copyright © 2017年 周筱雯. All rights reserved.
//

#import "UnbundlingViewController.h"
#import "MineViewModel.h"

@interface UnbundlingViewController ()

@property (weak, nonatomic) IBOutlet UILabel *unbundUserName;
@property (weak, nonatomic) IBOutlet UIButton *unbundClick;
@property (weak, nonatomic) IBOutlet UILabel *realName;
@property (weak, nonatomic) IBOutlet UILabel *cardNumber;

@property (nonatomic,strong) MineViewModel * mineViewModel;
@end

@implementation UnbundlingViewController

-(MineViewModel *) mineViewModel{
    if (!_mineViewModel) {
        _mineViewModel = [[MineViewModel alloc] init];
    }
    return _mineViewModel;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self.navigationItem setTitle:@"解除绑定"];
    [self.view setBackgroundColor:DEF_COLOR_F0F0F0];
    
    [self.unbundUserName setText:[NSString stringWithFormat:@"用户名： %@",UserInfoShare.userCenterModel.userName]];
    [self.realName setText:[NSString stringWithFormat:@"真实姓名：%@",UserInfoShare.userCenterModel.userRealName]];
    [self.cardNumber setText:[NSString stringWithFormat:@"身份证号：%@",UserInfoShare.userCenterModel.userIdCard]];
    
    /**
     解除绑定
     */
    [[self.unbundClick rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(id x) {
        [self alertView];
    }];
}

-(void) alertView {
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:nil message:@"确定解除绑定？" preferredStyle:UIAlertControllerStyleAlert];
    
    UIAlertAction * okAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
        
        [self unbundNetWork];
    }];
    
    
    UIAlertAction * cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }];
    
    [alertController addAction:okAction];
    [alertController addAction:cancelAction];
    
    [self presentViewController:alertController animated:YES completion:nil];
}

-(void) unbundNetWork{
    [MXUtility showMBProgress:self.view message:LoadingText];
    [[self.mineViewModel cancelBandRealInfoRequestParameter] subscribeNext:^(id x) {
        
        if ([x[@"errorcode"] integerValue] == 0) {
            
            
            [MXUtility showTips:@"解绑成功～"];
            [self.navigationController popToRootViewControllerAnimated:YES];
        }

        
        [MXUtility hideMBProgress:self.view];
    }error:^(NSError *error) {
        [MXUtility hideMBProgress:self.view];
    }];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
